/**
 *    Copyright (C) 2009, 2010 Victor Smirnov <aist11@gmail.com>
 *
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License along
 *    with this program; if not, write to the Free Software Foundation, Inc.,
 *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 *    See LICENSE.exceptions in the root folder of this project for possible
 *    exceptions
 *
 */

#include <decls.hpp>
#include <exceptions.hpp>
#include <natives.h>
#include <notifier.hpp>

JNIEXPORT jlong JNICALL REFLECTION_PKG(CoreFactory, getCoreFactory) (JNIEnv *env, jclass) {
	CUBEFS_EXC_BEGIN

	return Ptr2Handle(GetCoreFactory());

	CUBEFS_EXC_HANDLE
	return 0;
}

JNIEXPORT jlong JNICALL REFLECTION_PKG(CoreFactory, getCoreTypeSystem) (JNIEnv *env, jclass) {
	CUBEFS_EXC_BEGIN

	return Ptr2Handle(GetCoreFactory()->GetCoreTypeSystem());

	CUBEFS_EXC_HANDLE
	return 0;
}

JNIEXPORT jlong JNICALL REFLECTION_PKG(CoreFactory, CreateListOfTypes) (JNIEnv *env, jclass, jlong me, jint size) {
	CUBEFS_EXC_BEGIN

	CoreFactory* factory = Handle2Ptr<CoreFactory>(me);

	return Ptr2Handle(factory->CreateListOfTypes(size));

	CUBEFS_EXC_HANDLE
	return 0;
}

JNIEXPORT jlong JNICALL REFLECTION_PKG(CoreFactory, CreateListOfTyped) (JNIEnv *env, jclass, jlong me, jint size) {
	CUBEFS_EXC_BEGIN

	CoreFactory* factory = Handle2Ptr<CoreFactory>(me);

	return Ptr2Handle(factory->CreateListOfTyped(size));

	CUBEFS_EXC_HANDLE
	return 0;
}

JNIEXPORT jlong JNICALL REFLECTION_PKG(CoreFactory, CreateStaticListOfTyped) (JNIEnv *env, jclass, jlong me) {
	CUBEFS_EXC_BEGIN

	CoreFactory* factory = Handle2Ptr<CoreFactory>(me);

	return Ptr2Handle(factory->CreateStaticListOfTyped());

	CUBEFS_EXC_HANDLE
	return 0;
}

JNIEXPORT jlong JNICALL REFLECTION_PKG(CoreFactory, CreateListOfStrings) (JNIEnv *env, jclass, jlong me, jint size) {
	CUBEFS_EXC_BEGIN

	CoreFactory* factory = Handle2Ptr<CoreFactory>(me);

	return Ptr2Handle(factory->CreateListOfStrings(size));

	CUBEFS_EXC_HANDLE
	return 0;
}

JNIEXPORT jlong JNICALL REFLECTION_PKG(CoreFactory, CreateListOfBigInt) (JNIEnv *env, jclass, jlong me, jint size) {
	CUBEFS_EXC_BEGIN

	CoreFactory* factory = Handle2Ptr<CoreFactory>(me);

	return Ptr2Handle(factory->CreateListOfBigInt(size));

	CUBEFS_EXC_HANDLE
	return 0;
}





JNIEXPORT jlong JNICALL REFLECTION_PKG(CoreFactory, Create__JB) (JNIEnv *env, jclass, jlong me, jbyte value) {
	CUBEFS_EXC_BEGIN

	CoreFactory* factory = Handle2Ptr<CoreFactory>(me);

	return Ptr2Handle(factory->Create(value));

	CUBEFS_EXC_HANDLE
	return 0;
}

JNIEXPORT jlong JNICALL REFLECTION_PKG(CoreFactory, Create__JS) (JNIEnv *env, jclass, jlong me, jshort value) {
	CUBEFS_EXC_BEGIN

	CoreFactory* factory = Handle2Ptr<CoreFactory>(me);

	return Ptr2Handle(factory->Create(value));

	CUBEFS_EXC_HANDLE
	return 0;
}

JNIEXPORT jlong JNICALL REFLECTION_PKG(CoreFactory, Create__JC) (JNIEnv *env, jclass, jlong me, jchar value) {
	CUBEFS_EXC_BEGIN

	CoreFactory* factory = Handle2Ptr<CoreFactory>(me);

	return Ptr2Handle(factory->Create(value));

	CUBEFS_EXC_HANDLE
	return 0;
}

JNIEXPORT jlong JNICALL REFLECTION_PKG(CoreFactory, Create__JI) (JNIEnv *env, jclass, jlong me, jint value) {
	CUBEFS_EXC_BEGIN

	CoreFactory* factory = Handle2Ptr<CoreFactory>(me);

	return Ptr2Handle(factory->Create(value));

	CUBEFS_EXC_HANDLE
	return 0;
}

JNIEXPORT jlong JNICALL REFLECTION_PKG(CoreFactory, Create__JJ) (JNIEnv *env, jclass, jlong me, jlong value) {
	CUBEFS_EXC_BEGIN

	CoreFactory* factory = Handle2Ptr<CoreFactory>(me);

	return Ptr2Handle(factory->Create((BigInt)value));

	CUBEFS_EXC_HANDLE
	return 0;
}

JNIEXPORT jlong JNICALL REFLECTION_PKG(CoreFactory, Create__JF) (JNIEnv *env, jclass, jlong me, jfloat value) {
	CUBEFS_EXC_BEGIN

	CoreFactory* factory = Handle2Ptr<CoreFactory>(me);

	return Ptr2Handle(factory->Create(value));

	CUBEFS_EXC_HANDLE
	return 0;
}

JNIEXPORT jlong JNICALL REFLECTION_PKG(CoreFactory, Create__JD) (JNIEnv *env, jclass, jlong me, jdouble value) {
	CUBEFS_EXC_BEGIN

	CoreFactory* factory = Handle2Ptr<CoreFactory>(me);

	return Ptr2Handle(factory->Create(value));

	CUBEFS_EXC_HANDLE
	return 0;
}

JNIEXPORT jlong JNICALL REFLECTION_PKG(CoreFactory, Create__JZ) (JNIEnv *env, jclass, jlong me, jboolean value) {
	CUBEFS_EXC_BEGIN

	CoreFactory* factory = Handle2Ptr<CoreFactory>(me);

	return Ptr2Handle(factory->Create(value));

	CUBEFS_EXC_HANDLE
	return 0;
}

JNIEXPORT jlong JNICALL REFLECTION_PKG(CoreFactory, Create__JLjava_lang_String_2) (JNIEnv *env, jclass, jlong me, jstring value) {
	CUBEFS_EXC_BEGIN

	CoreFactory* factory = Handle2Ptr<CoreFactory>(me);

	const char *str = env->GetStringUTFChars(value, NULL);
	if (str == NULL) {
		return 0; /* OutOfMemoryError already thrown */
	}

	jlong handle = Ptr2Handle(factory->Create(str));

	env->ReleaseStringUTFChars(value, str);

	return handle;
	CUBEFS_EXC_HANDLE
	return 0;
}

JNIEXPORT jlong JNICALL REFLECTION_PKG(CoreFactory, CreateIDValue) (JNIEnv *env, jclass, jlong me, jstring value) {
	CUBEFS_EXC_BEGIN

	CoreFactory* factory = Handle2Ptr<CoreFactory>(me);

	const char *str = env->GetStringUTFChars(value, NULL);
	if (str == NULL) {
		return 0; /* OutOfMemoryError already thrown */
	}

	jlong handle = Ptr2Handle(factory->CreateIDValue(str));

	env->ReleaseStringUTFChars(value, str);

	return handle;
	CUBEFS_EXC_HANDLE
	return 0;
}

JNIEXPORT jlong JNICALL REFLECTION_PKG(CoreFactory, CreateVersion) (JNIEnv *env, jclass, jlong me, jstring value) {
	CUBEFS_EXC_BEGIN

	CoreFactory* factory = Handle2Ptr<CoreFactory>(me);

	const char *str = env->GetStringUTFChars(value, NULL);
	if (str == NULL) {
		return 0; /* OutOfMemoryError already thrown */
	}

	jlong handle = Ptr2Handle(factory->CreateVersion(str));

	env->ReleaseStringUTFChars(value, str);

	return handle;
	CUBEFS_EXC_HANDLE
	return 0;
}
